<?php

class LoginModel
{
    static public function tryLogin($email, $password)
    {
        $db = DbGateway::getConnection();

        $sql = '
            select
                u.*,
                ul.name as user_level_name
            from
                user as u
                join user_level as ul on (ul.id = u.user_level)
            where
                u.email=:email and
                u.password=:password
        ';
        $db->bindParam('email', $email);
        $db->bindParam('password', md5($password));

        $user_data = $db->fetchSingle($sql);
        if (!empty($user_data))
        {
            return $user_data;
        }

        return null;
    }
}

?>